package account

import (
	"context"
	"github.com/google/uuid"
	"github.com/spf13/cast"
	"insighttracking/query/dao"

	"insighttracking/apps/admin/internal/svc"
	"insighttracking/apps/admin/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
	"os"
)

type ModifyAccountApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewModifyAccountApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModifyAccountApiLogic {
	hostname, _ := os.Hostname()
	return &ModifyAccountApiLogic{
		Logger: logx.WithContext(ctx).WithCallerSkip(0).WithFields(
			logx.Field("Log_UUID", uuid.New().String()),
			logx.Field("hostname", hostname)),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ModifyAccountApiLogic) ModifyAccountApi(req *types.ModifyCurrentAccountReq) (resp string, err error) {
	accountId := l.ctx.Value("accountId")
	_, err = dao.AccountEntity.Where(dao.AccountEntity.AccountID.Eq(cast.ToInt64(accountId))).UpdateSimple(
		dao.AccountEntity.Avatar.Value(req.Avatar),
	)
	if err != nil {
		return "", err
	}
	return "修改成功", nil
}
